package patrol.mobile.com.mobilepatrol.activity.yanghuke.zuoyeshangbao;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.google.gson.Gson;

import java.util.HashMap;

import butterknife.BindView;
import okhttp3.Call;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.BaseActivity;
import patrol.mobile.com.mobilepatrol.activity.yanghuke.zuoyeshangbao.bean.WorkStatusBean;
import patrol.mobile.com.mobilepatrol.adapter.WorkStatusAdapter;
import patrol.mobile.com.mobilepatrol.api.Urls;
import patrol.mobile.com.mobilepatrol.utils.net.HttpCallBack;
import patrol.mobile.com.mobilepatrol.utils.net.HttpSender;

public class ZuoyeWanchengGzLActivity extends BaseActivity {
    @BindView(R.id.mEditSbr)
    TextView mEditSbr;
    @BindView(R.id.mEditSbsj)
    TextView mEditSbsj;
    @BindView(R.id.mEditQkms)
    TextView mEditQkms;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private String id;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_zuoyewanchengliang_layout;
    }

    @Override
    public void initData() {
        super.initData();
        id = getIntent().getStringExtra("id");
        tv_center_title.setVisibility(View.VISIBLE);
        iv_back.setVisibility(View.VISIBLE);
        tv_center_title.setText("完成工作量");
//        tv_right_title.setVisibility(View.VISIBLE);
//        tv_right_title.setText("保存");
        if (TextUtils.isEmpty(id)) {

        } else {
            httpData();
        }
    }

    @Override
    public void setListener() {
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void httpData() {
        HashMap<String, String> hashMap = new HashMap();
        hashMap.put("yhkOperationAreaId", id);
        HttpSender sender = new HttpSender(this, baseUrl, Urls.getYhkOperationWorksEntity);
        sender.requestPost(hashMap, new HttpCallBack(sender) {
            @Override
            public void onError(String code, Call call, Exception e) {

            }

            @Override
            public void onResponse(String code, String response) {
                Log.e("response", response);
                if (!TextUtils.isEmpty(response)) {
                    WorkStatusBean workStatusBean = new Gson().fromJson(response, WorkStatusBean.class);
                    mEditSbr.setText(workStatusBean.getWeather());
                    mEditSbsj.setText(workStatusBean.getWorksDate());
                    mEditQkms.setText(workStatusBean.getSituation());
                    recyclerView.setLayoutManager(new LinearLayoutManager(ZuoyeWanchengGzLActivity.this));
                    WorkStatusAdapter adapter = new WorkStatusAdapter(ZuoyeWanchengGzLActivity.this);
                    adapter.addItems(workStatusBean.getWorksList());
                    recyclerView.setAdapter(adapter);
                }
            }


        });
    }


}
